/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.reader.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import com.feiyue.basic.reader.util.DisplayUtil;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class DBHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "reader.db";
	private static final int DATABASE_VERSION = 12;
	private String FIELD_ID = "id";
	private String TABLE_NAME = "";
	private Context context;

	public DBHelper(Context paramContext) {
		super(paramContext, "reader.db", null, 12);
		this.context = paramContext;
	}

	public void delete(long paramLong) {
		SQLiteDatabase localSQLiteDatabase = getWritableDatabase();
		String str = this.FIELD_ID + "=?";
		String[] arrayOfString = new String[1];
		arrayOfString[0] = Long.toString(paramLong);
		localSQLiteDatabase.delete(this.TABLE_NAME, str, arrayOfString);
	}

	public void delete(long paramLong, int paramInt) {
		SQLiteDatabase localSQLiteDatabase = getWritableDatabase();
		String str = this.FIELD_ID + " = ? and type = ?";
		String[] arrayOfString = new String[2];
		arrayOfString[0] = Long.toString(paramLong);
		arrayOfString[1] = String.valueOf(paramInt);
		localSQLiteDatabase.delete(this.TABLE_NAME, str, arrayOfString);
	}

	public void delete(String paramString, int paramInt) {
		SQLiteDatabase localSQLiteDatabase = getWritableDatabase();
		String[] arrayOfString = new String[2];
		arrayOfString[0] = paramString;
		arrayOfString[1] = String.valueOf(paramInt);
		localSQLiteDatabase.delete(this.TABLE_NAME, " title = ? and type = ?",
				arrayOfString);
	}

	public void delete(int[] paramArrayOfInt) {
		int i = paramArrayOfInt.length;
		for (int j = 0;; ++j) {
			if (j >= i)
				return;
			delete(paramArrayOfInt[j]);
		}
	}

	public void init() {
		getReadableDatabase().close();
	}

	public long insert(ContentValues paramContentValues) {
		return getWritableDatabase().insert(this.TABLE_NAME, null,
				paramContentValues);
	}

	public void insert(List<ContentValues> paramList) {
		Iterator localIterator = paramList.iterator();
		while (true) {
			if (!(localIterator.hasNext()))
				return;
			insert((ContentValues) localIterator.next());
		}
	}

	public void onCreate(SQLiteDatabase paramSQLiteDatabase) {
		DisplayMetrics localDisplayMetrics = new DisplayMetrics();
		((WindowManager) this.context.getSystemService("window"))
				.getDefaultDisplay().getMetrics(localDisplayMetrics);
		int i = DisplayUtil.sp2px(18.0F, localDisplayMetrics.scaledDensity);
		Object[] arrayOfObject = new Object[1];
		arrayOfObject[0] = Integer.valueOf(i);
		String str = String
				.format("insert into setting (dayType, fontSize, textNum,light,bg) values ('0', '%d','500','3.3','0');",
						arrayOfObject);
		paramSQLiteDatabase
				.execSQL("Create table file_info (id integer primary key autoincrement,name text, icon integer,size integer,date text,type text,path text,nid text,pid integer);");
		paramSQLiteDatabase
				.execSQL("Create table file_record (id integer primary key autoincrement,path text,num integer,start_num integer,book_id integer,category_id integer,chapter_id integer,chapter_num integer);");
		paramSQLiteDatabase
				.execSQL("Create table setting (id integer primary key autoincrement,dayType integer,fontSize integer,textNum integer,light float,bg integer);");
		paramSQLiteDatabase.execSQL(str);
		paramSQLiteDatabase
				.execSQL("Create table content (id integer primary key autoincrement,title text,words text,nid text,ctno text,path text, cid text,icon integer);");
	}

	public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1,
			int paramInt2) {
	}

	public Cursor query(String[] paramArrayOfString1, String paramString1,
			String[] paramArrayOfString2, String paramString2,
			String paramString3, String paramString4) {
		try {
			Cursor localCursor = getReadableDatabase().query(this.TABLE_NAME,
					paramArrayOfString1, paramString1, paramArrayOfString2,
					paramString2, paramString3, paramString4);
			return localCursor;
		} catch (Exception localException) {
			localException.printStackTrace();
		}
		return null;
	}

	public Cursor queryAll() {
		try {
			Cursor localCursor = getReadableDatabase().query(this.TABLE_NAME,
					null, null, null, null, null, null);
			return localCursor;
		} catch (Exception localException) {
			localException.printStackTrace();
		}
		return null;
	}

	public void setTableName(String paramString) {
		this.TABLE_NAME = paramString;
	}

	public void update(long paramLong, ContentValues paramContentValues) {
		SQLiteDatabase localSQLiteDatabase = getWritableDatabase();
		String str = this.FIELD_ID + "=?";
		String[] arrayOfString = new String[1];
		arrayOfString[0] = String.valueOf(paramLong);
		localSQLiteDatabase.update(this.TABLE_NAME, paramContentValues, str,
				arrayOfString);
	}

	public void update(Map<Integer, ContentValues> paramMap) {
		Iterator localIterator = paramMap.keySet().iterator();
		while (true) {
			if (!(localIterator.hasNext()))
				return;
			int i = ((Integer) localIterator.next()).intValue();
			update(i, (ContentValues) paramMap.get(Integer.valueOf(i)));
		}
	}
}